package gui.utils;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.DefaultComboBoxModel;

public class NetworkInterfaceComboBoxModel extends DefaultComboBoxModel {

	private static final long serialVersionUID = 1L;

	public NetworkInterfaceComboBoxModel() {
		super();
		refresh();
	}

	// Creating the list of network interfaces into the comboBoxModel
	public final void refresh() {
		this.addElement("");
		Enumeration<NetworkInterface> nets;
		try {
			nets = NetworkInterface.getNetworkInterfaces();
			for (NetworkInterface netint : Collections.list(nets))
				this.addElement(netint.getName());
		} catch (SocketException ex) {
			Logger.getLogger(NetworkInterfaceComboBoxModel.class.getName())
					.log(Level.SEVERE, null, ex);
		}
	}
}
